package com.aptemo.webetek.server.handlers;

import java.util.ArrayList;

import com.aptemo.webetek.client.commands.Action;
import com.aptemo.webetek.client.commands.impl.GetPicksForEventAction;
import com.aptemo.webetek.client.commands.responses.ListResponse;
import com.aptemo.webetek.client.exceptions.BackendException;
import com.aptemo.webetek.client.exceptions.WebetekLoginException;
import com.aptemo.webetek.client.exceptions.BackendException.EErrorCodes;
import com.aptemo.webetek.server.data.WebetekUser;
import com.aptemo.webetek.server.datastore.DataStoreAPI;

public class PicksForEventHandler
		extends ActionHandler<GetPicksForEventAction, ListResponse<String>>
{

	public PicksForEventHandler(DataStoreAPI service)
	{
		super(service);
	}

	public Class<? extends Action<?>> getActionType()
	{
		return GetPicksForEventAction.class;
	}

	@Override
	public ListResponse<String> invoke(GetPicksForEventAction action) throws BackendException, WebetekLoginException
	{
		utils.checkLogin();
		// List<StakeBean> result = null;
		// if (action.getBetKey() != null && !action.getBetKey().isEmpty())
		// {
		// result = mparent.getStakes4Bet(action.getBetKey());
		// }
		// else if (action.getTeamKey() != null &&
		// !action.getTeamKey().isEmpty())
		// {
		// result = mparent.getStakes4Team(action.getTeamKey(),
		// action.getStatus());
		// }
		// else
		// {
		// result = mparent.getStakes(action.getStatus());
		// }
		//		
		WebetekUser user = utils.getCurrentUser(action.getTeamId());
		if (user == null)
		{
			throw new BackendException(EErrorCodes.NOT_TEAM_MEMBER);
		}
		String userId = user.getSid();

		ArrayList<String> result = (ArrayList<String>) dataService.getPicksForEvent(userId, action.getEventId());

		return new ListResponse<String>(result);
	}
}
